package com.example.xiaodu.yuejian12;

import android.app.Activity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.RadioButton;

import com.example.xiaodu.yuejian12.Fragment.ActivityFragment;
import com.example.xiaodu.yuejian12.Fragment.ClubFragment;
import com.example.xiaodu.yuejian12.Fragment.HomeFragment;
import com.example.xiaodu.yuejian12.Fragment.MeFragment;
import com.example.xiaodu.yuejian12.Fragment.ShowFragment;
import com.example.xiaodu.yuejian12.Fragment.TrainFragment;

public class MainActivity extends AppCompatActivity {
    private RadioButton rb1,rb2,rb3,rb4,rb5;
    private FragmentTransaction fragmentTransaction;
    private FragmentManager fragmentManager;
    private TrainFragment trainFragment;
    private ClubFragment clubFragment;
    private HomeFragment homeFragment;
    private ShowFragment showFragment;
    private MeFragment meFragment;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        rb1=(RadioButton)findViewById(R.id.radio_button1);
        rb2=(RadioButton)findViewById(R.id.radio_button2);
        rb3=(RadioButton)findViewById(R.id.radio_button3);
        rb4=(RadioButton)findViewById(R.id.radio_button4);
        rb5=(RadioButton)findViewById(R.id.radio_button5);

        rb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    if(trainFragment==null){
                        trainFragment=new TrainFragment();
                    }
                    fragmentTransaction=fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.framelayout,trainFragment);
                    fragmentTransaction.commit();
                }
            }
        });


        rb2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    if(clubFragment==null){
                        clubFragment=new ClubFragment();
                    }
                    fragmentTransaction=fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.framelayout,clubFragment);
                    fragmentTransaction.commit();
                }
            }
        });

        rb3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    if(homeFragment==null){
                        homeFragment=new HomeFragment();
                    }
                    fragmentTransaction=fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.framelayout,homeFragment);
                    fragmentTransaction.commit();
                }
            }
        });

        rb4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    if(showFragment==null){
                        showFragment=new ShowFragment();
                    }
                    fragmentTransaction=fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.framelayout,showFragment);
                    fragmentTransaction.commit();
                }
            }
        });

        rb5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    if(meFragment==null){
                        meFragment=new MeFragment();
                    }
                    fragmentTransaction=fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.framelayout,meFragment);
                    fragmentTransaction.commit();
                }
            }
        });
        fragmentManager=getSupportFragmentManager();
        rb1.setChecked(true);


    }



}
